//package com.lk.labsystem.config;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@Component
//public class TokenInterceptor extends HandlerInterceptorAdapter {
//    @Autowired
//    private JwtConfig jwtConfig;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String uri = request.getRequestURI();
//        if(uri.contains("/Login")) {
//            return true;
//        }
//        String token=request.getHeader(jwtConfig.getHeader());
//        if(StringUtils.isEmpty(token)){
//            token=request.getParameter(jwtConfig.getHeader());
//        }
//        if(StringUtils.isEmpty(token)){
//            //401 token不能为空
//            sendError(response,"token不能为空");
//            return false;
//        }
//        try {
//            jwtConfig.getTokenClaim(token);
//        } catch (Exception e) {
////            throw new RuntimeException(e);401 token失效
//            sendError(response,"token过期");
//            return false;
//        }
//        return true;
//    }
//
//    private void sendError(HttpServletResponse response, String msg) throws IOException {
//        response.setStatus(401);
//        response.setContentType("application/json;charset=UTF-8");
//        response.setCharacterEncoding("UTF-8");
//        response.getWriter().write(msg);
//    }
//}
